package cn.hm.search.controller;

import cn.hm.search.api.feign.SkuFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * @author Mxb
 * @version 1.0
 * @date 2020/10/4 8:01
 */
@Controller
@RequestMapping(value = "/search")
public class SkuController {
    /**
     * 使用Feign调用搜索微服务
     */
    @Autowired
    private SkuFeign skuFeign;

    /**
     * 搜索
     * @param searchMap
     * @return
     */
    @GetMapping(value = "/list")
    public String search(@RequestParam(required = false) Map<String,String> searchMap, Model model){
        //调用changgou-service-search微服务
        Map<String,Object> resultMap = skuFeign.search(searchMap);
        // 将商品信息放入域中
        model.addAttribute("result",resultMap);
        // 将条件存储，用于页面回显数据
        model.addAttribute("searchMap",searchMap);
        return "search";
    }
}
